package com.mzm.ui.admin;

import java.util.Arrays;
import java.util.HashSet;

import org.apache.commons.lang.StringUtils;

import com.mzm.api.ProductInfoDto;
import com.mzm.api.ProductType;

/**
 * 
 * @author User
 */
public class ProductInfoEditorPanel extends javax.swing.JPanel {

	/**
	 * Creates new form RecommendationEditorPanel
	 */
	public ProductInfoEditorPanel() {
		initComponents();
	}

	public ProductType getProductType() {
		if("חפץ".equals(productTypeComb.getSelectedItem())){
			return ProductType.ARTIFACT;
		}
		return ProductType.SERVICE;
	}

	public void setProductType(ProductType productType) {
		if(ProductType.ARTIFACT.equals(productType)){
			productTypeComb.setSelectedItem("חפץ");
		}
		else {
			productTypeComb.setSelectedItem("שירות");
		}
	}

	/**
	 * Clears the text box.
	 */
	public void clear(){
		nameTF.setText("");
		remarksTA1.setText("");
		urlsTA.setText("");
	}
	
	/**
	 * Gets the <code>RecommendationDto</code> represented by this editor.
	 * 
	 * @return
	 */
	public ProductInfoDto getProductInfoDto() {
		ProductInfoDto productInfo = new ProductInfoDto();
		productInfo.setProductName(nameTF.getText());
		productInfo.setProductType(getProductType());
		String[] urls = StringUtils.split(urlsTA.getText());
		productInfo.setUrls(new HashSet<String>(Arrays.asList(urls)));
		return productInfo;
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane4 = new javax.swing.JScrollPane();
        remarksTA1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        nameTF = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        urlsTA = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        productTypeComb = new javax.swing.JComboBox();

        remarksTA1.setColumns(20);
        remarksTA1.setRows(5);
        jScrollPane4.setViewportView(remarksTA1);

        jLabel1.setText("שם המוצר:");

        jLabel2.setText("כתובות URL:");

        urlsTA.setColumns(20);
        urlsTA.setRows(5);
        jScrollPane1.setViewportView(urlsTA);

        jLabel3.setText("סוג המוצר:");

        productTypeComb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "חפץ", "שירות" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(97, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(nameTF, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 381, Short.MAX_VALUE))
                    .addComponent(productTypeComb, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(productTypeComb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(24, 24, 24))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTextField nameTF;
    private javax.swing.JComboBox productTypeComb;
    private javax.swing.JTextArea remarksTA1;
    private javax.swing.JTextArea urlsTA;
    // End of variables declaration//GEN-END:variables

}
